import React, { Component, PureComponent } from 'react'

// 高阶组件
function enhanceRegionProps(WrappedComponent) {
  return props => {
    return <WrappedComponent {...props} region="中国" />
  }
}

class Home extends PureComponent {
  render() {
    return <h2>Home: {`nickname: ${this.props.nickname}  grade: ${this.props.level} region: ${this.props.region}` }</h2>
  }
}

const EnhanceHome = enhanceRegionProps(Home)

class About extends PureComponent {
  render() {
    return <h2>About: {`nickname: ${this.props.nickname}  grade: ${this.props.level} region: ${this.props.region}`}</h2>
  }
}

const EnhanceAbout = enhanceRegionProps(About)

class App extends Component {
  render() {
    return (
      <div>
        App:
        <EnhanceHome nickname="yz" level={90} region="中国" />
        <EnhanceAbout nickname="yz" level={90} region="中国" />
      </div>
    )
  }
}

export default App
